package myTest.function


fun main(args: Array<String>) {
//    test("HelloWorld")
//    testMulti3.invoke(1, 2, 3)
//    testSub(4, 3)
    testLambda(1, test) { it: Int ->
        val result = it * 2
        println(result)
        result
    }

//    funLambda(::testName)

    funLambda {
        println(it)
        it
    }

    arrayListOf(1, 2, 3, 4, 5).forEach Loop@{

        if (it == 3) {
            return@Loop
        }

        println(it)
    }

    println("-----------End")


}

val test = {
    println("HelloWorld")
}

fun testId(id: Int) = println("$id")

fun funLambda(action: (String) -> String) {
    println("我爱${action("二珂")}")
}

fun testName(name: String): String {
    println("$name")
    return name
}


val testAdd = fun(num1: Int, num2: Int) = {
    println("$num1+$num2=${num1 + num2}")
    num1 + num2
}

val testSub = fun(sum: Int, num1: Int) = {
    println("$sum-$num1=${sum - num1}")
    sum - num1
}

val testMulti3 = { num1: Int, num2: Int, _: Int -> println("$num1*$num2=${num1 * num2}") }

val testLambdaNoParams = { println("---------") }

val testLambda1 = { msg: String -> msg }

/**
 * action: () -> Unit :lambda表达式作为参数
 */
fun testLambda(num: Int, actionZero: () -> Unit, action1: (Int) -> Int) {
    actionZero()
    action1.invoke(num)
    println("$num")
}


